package com.situ.personal.service;

import java.util.List;

import com.situ.personal.dao.RoleDao;
import com.situ.personal.entity.Department;
import com.situ.personal.entity.PageInfo;
import com.situ.personal.entity.Role;

public class RoleService {
	RoleDao roleDao  = new RoleDao();

	public List<Role> findAll() {
		List<Role> roleList = roleDao.findAll();
		return roleList;
	}

	public PageInfo findByPage(int pageNo, int pageSize) {
		PageInfo pageInfo = new PageInfo();
		
		pageInfo.setPageNo(pageNo);
		pageInfo.setPageSize(pageSize);
		
		//总页数
		int count = roleDao.getTotalPage();
		int totalPage = (int)Math.ceil( (double)count / pageSize); 
		pageInfo.setTotalPage(totalPage);
		
		//每页信息List
		int offset = (pageNo-1)*pageSize;
		List<Role> list = roleDao.findByPage(offset, pageSize);
		pageInfo.setList(list);
		
		return pageInfo;
	}

	public boolean deleteById(int id) {
		boolean isDelete = roleDao.deleteById(id);
		return isDelete;
	}

	public boolean insertRole(String roleName, String roleSn) {
		boolean isInsert = roleDao.insertRole(roleName,roleSn);
		return isInsert;
	}

	public Role selectById(int RoleId) {
		return roleDao.selectById(RoleId);
	}

	public boolean updateRoleInfo(int id, String name, String sn) {
		
		return roleDao.updateRoleInfo(id,name,sn);
	}

}
